﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Xml;
using System.Xml.Serialization;

namespace Webcar.BLL
{
    public static class PermissionManager
    {
        public const string View="查看";
        public const string Modify="修改";
        public const string Module_CAR = "车辆管理";
        public const string Module_REPAIR = "车辆维修";
        public const string Module_DRIVER = "驾驶员管理";
        public const string Module_SEC = "安全管理";
        public const string Module_REPORT = "工作汇报";
        public const string Module_SYSTEM = "系统管理";


        public static Permission 上传文件 = new Permission() { PermissionId = "upload_file", PermissionType = Modify, Module = Module_SYSTEM, Name = "上传文件" };
        public static Permission 编辑车辆档案 = new Permission() { PermissionId = "modify_car", PermissionType = Modify, Module = Module_CAR, Name = "编辑车辆档案" };
        //public static Permission 查看车辆保险 = new Permission() { PermissionId = "view_insure", PermissionType = View, Module = Module_CAR, Name = "查看车辆保险" };
        public static Permission 编辑车辆保险 = new Permission() { PermissionId = "modify_insure", PermissionType = Modify, Module = Module_CAR, Name = "编辑车辆保险" };
        //public static Permission 查看车辆油耗里程 = new Permission() { PermissionId = "view_oil", PermissionType = View, Module = Module_CAR, Name = "查看车辆油耗里程" };
        public static Permission 编辑单车成本 = new Permission() { PermissionId = "modify_car_cost", PermissionType = Modify, Module = Module_CAR, Name = "编辑单车成本" };
        public static Permission 调动车辆 = new Permission() { PermissionId = "move_car", PermissionType = Modify, Module = Module_CAR, Name = "调动车辆" };
        public static Permission 报废车辆 = new Permission() { PermissionId = "discard_car", PermissionType = Modify, Module = Module_CAR, Name = "报废车辆" };


        public static Permission 编辑维修单 = new Permission() { PermissionId = "modify_repair", PermissionType = Modify, Module = Module_REPAIR, Name = "编辑维修单" };
        public static Permission 编辑驾驶员 = new Permission() { PermissionId = "modify_driver", PermissionType = Modify, Module = Module_DRIVER, Name = "编辑驾驶员" };
        public static Permission 调动驾驶员 = new Permission() { PermissionId = "move_driver", PermissionType = Modify, Module = Module_DRIVER, Name = "调动驾驶员" };
        public static Permission 编辑驾驶安全学习 = new Permission() { PermissionId = "modify_study", PermissionType = Modify, Module = Module_DRIVER, Name = "编辑驾驶安全学习" };
        public static Permission 编辑安全事故 = new Permission() { PermissionId = "modify_sec", PermissionType = Modify, Module = Module_SEC, Name = "编辑安全事故" };

        public static Permission 填写派车单 = new Permission() { PermissionId = "modify_car_send", PermissionType = Modify, Module = Module_CAR, Name = "填写派车单" };

        public static Permission 派车审核权限 = new Permission() { PermissionId = "check_car_send", PermissionType = Modify, Module = Module_CAR, Name = "派车审核权限" };
        public static Permission 派车删除权限 = new Permission() { PermissionId = "check_car_delete", PermissionType = Modify, Module = Module_CAR, Name = "派车删除权限" };

        public static Permission 填写情况汇报 = new Permission() { PermissionId = "modify_report", PermissionType = Modify, Module = Module_REPORT, Name = "填写情况汇报" };
        //public static Permission 发布工作动态 = new Permission() { PermissionId = "modify_work", PermissionType = Modify, Module = Module_SYSTEM, Name = "发布工作动态" };
        //public static Permission 发布预警信息 = new Permission() { PermissionId = "modify_warn", PermissionType = Modify, Module = Module_SYSTEM, Name = "发布预警信息" };
        //public static Permission 删除通讯录 = new Permission() { PermissionId = "modify_warn", PermissionType = Modify, Module = Module_SYSTEM, Name = "发布预警信息" };

        
        public static Permission 填写无功运行记录 = new Permission() { PermissionId = "modify_runrecord", PermissionType = Modify, Module = Module_REPORT, Name = "填写无功运行记录" };
        public static Permission 填写GPS统计表 = new Permission() { PermissionId = "modify_gps_tj", PermissionType = Modify, Module = Module_REPORT, Name = "填写GPS统计表" };

        public static Permission 编辑系统操作员 = new Permission() { PermissionId = "modify_user", PermissionType = Modify, Module = Module_SYSTEM, Name = "编辑系统操作员" };
        public static Permission 系统单位设置 = new Permission() { PermissionId = "modify_dept", PermissionType = Modify, Module = Module_SYSTEM, Name = "系统单位设置" };
        

        public static void LoadPermissions()
        {
            var list = typeof(PermissionManager).GetFields(BindingFlags.Static | BindingFlags.Public).Where(a=>a.FieldType==typeof(Permission));
            AllPermissions = list.Select(a => a.GetValue(null) as Permission).ToArray();
            //XmlSerializer serial = new XmlSerializer(typeof(Permissions));
            //Permissions list = (Permissions)serial.Deserialize(new FileStream(filename, FileMode.Open, FileAccess.Read));
            //AllPermissions = list.List;
        }
        static PermissionManager()
        {
            LoadPermissions();
        }
        public static Permission[] AllPermissions
        {
            get;
            set;
        }

    }
    //[XmlRoot]
    //public class Permissions
    //{
    //    [XmlElement("Permission")]
    //    public Permission[] List
    //    {
    //        get;
    //        set;
    //    }
    //}
    [XmlType]
    public class Permission
    {
        [XmlAttribute]
        public string PermissionId
        {
            get;
            set;
        }
        [XmlAttribute]
        public string PermissionType
        {
            get;
            set;
        }
        [XmlAttribute]
        public string Module
        {
            get;
            set;
        }
        [XmlAttribute]
        public string Name
        {
            get;
            set;
        }
        //[XmlAttribute]
        //public string Url
        //{
        //    get;
        //    set;
        //}
    }

}